import 'package:lcapp/model/db/sql_constant.dart';
import 'package:lcapp/model/db/sqlite.dart';
import 'package:sqflite/sqflite.dart';

class BaseDBOperate {

  //查询APP的更新记录
  static Future<Map> getUpgradeRecord(int versionCode) async {
    Database baseDb = await SqliteSingleton.getInstance().getBaseDB();
    Map recordData = {};
    List queryResult = await baseDb.rawQuery(
        'SELECT * ' + 'FROM  $TB_UPGRADE_RECORD  ' + 'WHERE version_code = ?',
        [versionCode]);
    if (queryResult != null && queryResult.length > 0) {
      recordData = queryResult[0];
    }
    return recordData;
  }

  //插入APP更新记录
  static Future<int> insertUpgradeRecord(Map<String, dynamic> data) async {
    Database baseDb = await SqliteSingleton.getInstance().getBaseDB();
    int result = await baseDb.insert(TB_UPGRADE_RECORD, data);
    return result;
  }
  //更新APP更新记录
  static Future<int> updateUpgradeRecord(int versionCode) async {
    Database baseDb = await SqliteSingleton.getInstance().getBaseDB();
    int result = await baseDb.update(TB_UPGRADE_RECORD, {"ignore": 0,},
        where: "version_code = ?", whereArgs: [versionCode]);
    return result;
  }

}